package com.heima.user.controller.v1;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.common.dtos.ResponseResult;
import com.heima.common.util.BeanHelper;
import com.heima.model.user.dtos.UserInfoDto;
import com.heima.model.user.dtos.UserRelationDto;
import com.heima.user.entity.ApUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.user.service.IApUserService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * APP用户信息表 前端控制器
 * </p>
 *
 * @author heima
 * @since 2021-03-13
 */
@RestController
@RequestMapping("/api/v1/user")
@Api(tags = "APP用户信息表接口")
@CrossOrigin
public class ApUserController{

    @Autowired
    private IApUserService apUserService;

    /**
     * 用户关注和取消关注作者功能
     */
    @PostMapping("/user_follow")
    public ResponseResult userFollow(@RequestBody UserRelationDto dto){
        apUserService.userFollow(dto);
        return ResponseResult.ok();
    }

    /**
     * 根据用户id和关注作者的id查询
     * @param userId
     * @param followId
     * @return
     */
    @GetMapping("/isUserFollow")
    public Boolean findByUserIdAndFollowId(@RequestParam(name = "userId") Integer userId,
                                    @RequestParam(name = "followId") Integer followId){
       return apUserService.findByUserIdAndFollowId(userId,followId);
    }

    /**
     * 查询用户信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public UserInfoDto findUserById(@PathVariable(name="id") Integer id){
        ApUser apUser = apUserService.getById(id);
        if(apUser!=null){
           return BeanHelper.copyProperties(apUser,UserInfoDto.class);
        }
        return null;
    }

}
